home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / AUTOCK3.PAK / ACLIKDOC.CPP next >
C/C++ Source or Header  |  1997-05-06  |  5KB  |  201 lines

  1. // AClikDoc.cpp : implementation of the CAutoClickDoc class
  2. //
  3. // This is a part of the Microsoft Foundation Classes C++ library.
  4. // Copyright (C) 1992-1995 Microsoft Corporation
  5. // All rights reserved.
  6. //
  7. // This source code is only intended as a supplement to the
  8. // Microsoft Foundation Classes Reference and related
  9. // electronic documentation provided with the library.
  10. // See these sources for detailed information regarding the
  11. // Microsoft Foundation Classes product.
  12.  
  13. #include "stdafx.h"
  14. #include "AutoClik.h"
  15.  
  16. #include "AClikDoc.h"
  17. #include "Dialogs.h"
  18. #include "ClikPnt.h"
  19.  
  20. #ifdef _DEBUG
  21. #define new DEBUG_NEW
  22. #undef THIS_FILE
  23. static char THIS_FILE[] = __FILE__;
  24. #endif
  25.  
  26. /////////////////////////////////////////////////////////////////////////////
  27. // CAutoClickDoc
  28.  
  29. IMPLEMENT_DYNCREATE(CAutoClickDoc, CDocument)
  30.  
  31. BEGIN_MESSAGE_MAP(CAutoClickDoc, CDocument)
  32.     //{{AFX_MSG_MAP(CAutoClickDoc)
  33.     ON_COMMAND(ID_EDIT_CHANGETEXT, OnEditChangetext)
  34.     //}}AFX_MSG_MAP
  35. END_MESSAGE_MAP()
  36.  
  37. BEGIN_DISPATCH_MAP(CAutoClickDoc, CDocument)
  38.     //{{AFX_DISPATCH_MAP(CAutoClickDoc)
  39.     DISP_PROPERTY(CAutoClickDoc, "text", m_str, VT_BSTR)
  40.     DISP_PROPERTY_EX(CAutoClickDoc, "x", GetX, SetX, VT_I2)
  41.     DISP_PROPERTY_EX(CAutoClickDoc, "y", GetY, SetY, VT_I2)
  42.     DISP_PROPERTY_EX(CAutoClickDoc, "Position", GetPosition, SetPosition, VT_DISPATCH)
  43.     DISP_FUNCTION(CAutoClickDoc, "RefreshWindow", Refresh, VT_EMPTY, VTS_NONE)
  44.     DISP_FUNCTION(CAutoClickDoc, "SetAllProps", SetAllProps, VT_EMPTY, VTS_I2 VTS_I2 VTS_BSTR)
  45.     DISP_FUNCTION(CAutoClickDoc, "ShowWindow", ShowWindow, VT_EMPTY, VTS_NONE)
  46.     //}}AFX_DISPATCH_MAP
  47. END_DISPATCH_MAP()
  48.  
  49. // Note: we add support for IID_IAClick to support typesafe binding
  50. //  from VBA.  This IID must match the GUID that is attached to the 
  51. //  dispinterface in the .ODL file.
  52.  
  53. // {47D53E05-CC33-11CE-8F35-00DD01109044}
  54. static const IID IID_IAClick =
  55. { 0x47d53e05, 0xcc33, 0x11ce, { 0x8f, 0x35, 0x0, 0xdd, 0x1, 0x10, 0x90, 0x44 } };
  56.  
  57. BEGIN_INTERFACE_MAP(CAutoClickDoc, CDocument)
  58.     INTERFACE_PART(CAutoClickDoc, IID_IAClick, Dispatch)
  59. END_INTERFACE_MAP()
  60.  
  61. /////////////////////////////////////////////////////////////////////////////
  62. // CAutoClickDoc construction/destruction
  63.  
  64. CAutoClickDoc::CAutoClickDoc()
  65. {
  66.     EnableAutomation();
  67.     m_pt = CPoint(10, 10);
  68.     m_str = _T("Automation!");
  69.  
  70.     AfxOleLockApp();
  71. }
  72.  
  73. CAutoClickDoc::~CAutoClickDoc()
  74. {
  75.     AfxOleUnlockApp();
  76. }
  77.  
  78. BOOL CAutoClickDoc::OnNewDocument()
  79. {
  80.     if (!CDocument::OnNewDocument())
  81.         return FALSE;
  82.  
  83.     // TODO: add reinitialization code here
  84.     // (SDI documents will reuse this document)
  85.  
  86.     return TRUE;
  87. }
  88.  
  89. void CAutoClickDoc::Refresh()
  90. {
  91.     UpdateAllViews(NULL);
  92.     SetModifiedFlag();
  93. }
  94.  
  95. /////////////////////////////////////////////////////////////////////////////
  96. // CAutoClickDoc serialization
  97.  
  98. void CAutoClickDoc::Serialize(CArchive& ar)
  99. {
  100.     if (ar.IsStoring())
  101.     {
  102.         ar << m_pt << m_str;
  103.     }
  104.     else
  105.     {
  106.         ar >> m_pt >> m_str;
  107.     }
  108. }
  109.  
  110. /////////////////////////////////////////////////////////////////////////////
  111. // CAutoClickDoc diagnostics
  112.  
  113. #ifdef _DEBUG
  114. void CAutoClickDoc::AssertValid() const
  115. {
  116.     CDocument::AssertValid();
  117. }
  118.  
  119. void CAutoClickDoc::Dump(CDumpContext& dc) const
  120. {
  121.     CDocument::Dump(dc);
  122. }
  123. #endif //_DEBUG
  124.  
  125. /////////////////////////////////////////////////////////////////////////////
  126. // CAutoClickDoc commands
  127.  
  128. void CAutoClickDoc::OnEditChangetext() 
  129. {
  130.     CChangeText dlg;
  131.     dlg.m_str = m_str;
  132.     if (dlg.DoModal())
  133.     {
  134.         m_str = dlg.m_str;
  135.         Refresh();
  136.     }
  137. }
  138.  
  139. short CAutoClickDoc::GetX()
  140. {
  141.     return (short)m_pt.x;
  142. }
  143.  
  144. void CAutoClickDoc::SetX(short nNewValue)
  145. {
  146.     m_pt.x = nNewValue;
  147.     Refresh();
  148. }
  149.  
  150. short CAutoClickDoc::GetY()
  151. {
  152.     return (short)m_pt.y;
  153. }
  154.  
  155. void CAutoClickDoc::SetY(short nNewValue)
  156. {
  157.     m_pt.y = nNewValue;
  158.     Refresh();
  159. }
  160.  
  161. void CAutoClickDoc::SetAllProps(short x, short y, LPCTSTR text)
  162. {
  163.     m_pt.x = x;
  164.     m_pt.y = y;
  165.     m_str = text;
  166.     Refresh();
  167. }
  168.  
  169. void CAutoClickDoc::ShowWindow()
  170. {
  171.     POSITION pos = GetFirstViewPosition();
  172.     CView* pView = GetNextView(pos);
  173.     if (pView != NULL)
  174.     {
  175.         CFrameWnd* pFrameWnd = pView->GetParentFrame();
  176.         pFrameWnd->ActivateFrame(SW_SHOW);
  177.         pFrameWnd = pFrameWnd->GetParentFrame();
  178.         if (pFrameWnd != NULL)
  179.             pFrameWnd->ActivateFrame(SW_SHOW);
  180.     }
  181. }
  182.  
  183. LPDISPATCH CAutoClickDoc::GetPosition() 
  184. {
  185.     CAutoClickPoint* pPos = new CAutoClickPoint;
  186.     pPos->SetClickPoint(m_pt);
  187.  
  188.     LPDISPATCH lpResult = pPos->GetIDispatch(FALSE);
  189.     return lpResult;
  190. }
  191.  
  192. void CAutoClickDoc::SetPosition(LPDISPATCH newValue) 
  193. {
  194.     CAutoClickPoint* pPos = (CAutoClickPoint*)CCmdTarget::FromIDispatch(newValue);
  195.     if (pPos != NULL && pPos->IsKindOf(RUNTIME_CLASS(CAutoClickPoint)))
  196.     {
  197.         m_pt = pPos->GetClickPoint();
  198.         Refresh();
  199.     }
  200. }
  201.